<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
const isMac = navigator.platform.indexOf('Mac') === 0;
const kBehaviors = window.internals ? ['mac', 'win'] : isMac ? ['mac'] : ['win'];
for (const behavior of kBehaviors) {
  if (window.internals) {
    internals.settings.setEditingBehavior(behavior);
    internals.settings.setSelectTrailingWhitespaceEnabled(behavior !== 'mac');
  }

selection_test(
  '<div contenteditable dir="rtl">|\n Just\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n |Just\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-0 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n| Just\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n |Just\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-1 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n |Just\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n |Just\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-2 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n J|ust\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n |J^ust\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-3 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Ju|st\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n |Ju^st\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-4 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Jus|t\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n |Jus^t\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-5 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just|\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n |Just^\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-6 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n| <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n |Just\n^ <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-7 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>|testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n |Just\n^ <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-8 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>t|esting \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>|t^esting \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-9 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>te|sting \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>|te^sting \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-10 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>tes|ting \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>|tes^ting \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-11 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>test|ing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>|test^ing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-12 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>testi|ng \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>|testi^ng \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-13 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>testin|g \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>|testin^g \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-14 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>testing| \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>|testing^ \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-15 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>testing |\u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>|testing ^\u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-16 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8|\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>testing |\u05E8^\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-17 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8\u05E7</span>|\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>testing |\u05E8\u05E7^</span>\n \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-18 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8\u05E7</span>\n| \u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>testing |\u05E8\u05E7</span>\n^ \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-19 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8\u05E7</span>\n |\u05D1\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>testing |\u05E8\u05E7</span>\n^ \u05D1\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-20 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8\u05E7</span>\n \u05D1|\u05D5\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8\u05E7</span>\n |\u05D1^\u05D5\u05D3\u05E7\n</div>',
  `${behavior} 14-21 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5|\u05D3\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8\u05E7</span>\n |\u05D1\u05D5^\u05D3\u05E7\n</div>',
  `${behavior} 14-22 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3|\u05E7\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8\u05E7</span>\n |\u05D1\u05D5\u05D3^\u05E7\n</div>',
  `${behavior} 14-23 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7|\n</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8\u05E7</span>\n |\u05D1\u05D5\u05D3\u05E7^\n</div>',
  `${behavior} 14-24 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8\u05E7</span>\n \u05D1\u05D5\u05D3\u05E7\n|</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\n Just\n <span>testing \u05E8\u05E7</span>\n |\u05D1\u05D5\u05D3\u05E7^\n</div>',
  `${behavior} 14-25 rtl backward word`);
}
</script>
